﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dycox.Drawing;

namespace Dycox.Windows.Forms
{
    public class DiagramControlHost : DiagramShape
    {
        public DiagramControlHost(Control targetControl)
        {
            if (targetControl == null)
                throw new ArgumentNullException("targetControl");

            _targetControl = targetControl;

            SetHotPoints(DiagramRectangle.GetHotPoints(targetControl.Bounds));

            //_targetControl.LocationChanged += ControlBoundsChanged;
            _targetControl.Move += ControlBoundsChanged;
            _targetControl.SizeChanged += ControlBoundsChanged;
        }

        void ControlBoundsChanged(object sender, EventArgs e)
        {
            SetHotPoints(DiagramRectangle.GetHotPoints(_targetControl.Bounds));
        }

        private Control _targetControl;

        public Control TargetControl
        {
            get { return _targetControl; }
        }

        protected override void DrawShape(DrawShapeArgs g)
        {

        }

        public override bool HitTest(Point location, Graphics g)
        {
            return _targetControl.Bounds.Contains(location);
        }

        public override void Dispose()
        {
            base.Dispose();

            _targetControl.Move -= ControlBoundsChanged;
            _targetControl.SizeChanged -= ControlBoundsChanged;

        }
    }

}
